<?php
/**
 * Created by PhpStorm.
 * User: qhzhyt
 * Date: 2018/10/4
 * Time: 17:37
 */

//md5(crypt(md5($pass),substr($pass,0,2)))
function pwCheck($password,$saved){
    return md5(crypt(md5($password),substr($password,0,2)))===$saved;
}

function cryptPassword($password){
    return md5(crypt(md5($password),substr($password,0,2)));
}

function validate_email($email){
    $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
    $temp=explode("@",$email);
    if(preg_match($pattern,$email)){ //先用正则表达式验证email格式的有效性
        if(checkdnsrr(array_pop($temp),"MX")){//再用checkdnsrr验证email的域名部分的有效性
            return true;
        }else{
            return false;
        }
    }else{
        return false;
    }
}